﻿using System;
using System.Runtime.Serialization;
using ArtheaEngine;
using NLog;

namespace ArtheaServer.Commands
{
    public class QuitCommand : Command
    {
        private static readonly Logger log = LogManager.GetCurrentClassLogger();

        public QuitCommand() : base("quit", "Exits the game.")
        {
        }

        #region Overrides of Command

        public override void Execute(Character ch, Argument argument)
        {
            if (!(ch is Player))
                return;

            var p = ch as Player;

            p.WriteLine("Good-bye!");
            log.Info(p.Name + " has logged out");
            throw new QuitCommandException();
        }

        #endregion
    }

    [Serializable]
    public class QuitCommandException : Exception
    {
        //
        // For guidelines regarding the creation of new exception types, see
        //    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconerrorraisinghandlingguidelines.asp
        // and
        //    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp07192001.asp
        //

        public QuitCommandException()
        {
        }

        public QuitCommandException(string message) : base(message)
        {
        }

        public QuitCommandException(string message, Exception inner) : base(message, inner)
        {
        }

        protected QuitCommandException(
            SerializationInfo info,
            StreamingContext context) : base(info, context)
        {
        }
    }
}